﻿@{
    Layout = null;
    var list = ViewBag.listMy as List<FileInfoMy>;
}
@using SQLiteCoreDB.Models;
@using System.Text.RegularExpressions
@if (list != null && list.Count != 0)
{
    foreach (var item in list)
    {

        @* string extend = Path.GetExtension(item.FileName).ToLower(); *@
        string supportedExtensionsPattern = @"\.(jpg|jpeg|png|jfif|gif|bmp|webp|ico)$";
        bool imgIs = !string.IsNullOrWhiteSpace(item.FileName) && Regex.IsMatch(item.FileName, supportedExtensionsPattern, RegexOptions.IgnoreCase);
        bool IsMd = !string.IsNullOrWhiteSpace(item.FileName) && System.IO.Path.GetExtension(item.FileName).Equals(".md", StringComparison.OrdinalIgnoreCase);
        <tr>
            <td>
                <span class="itemCell">@item.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")</span>
            </td>
            @{
                int index = item.FileName.IndexOf('_');

                if (index >= 0 && index < item.FileName.Length - 1)
                {
                    item.FileName = item.FileName.Substring(index + 1); // 获取从下划线后面开始的子字符串
                }
            }
            @if (string.IsNullOrEmpty(item.FileSize))
            {
                <td>   <span class="itemCell"><a href="/home/SeeDir?dirNew=@item.FileNamePath" style="color: #1e9fff;"><i class="layui-icon layui-icon-export"></i>@item.FileName</a></span></td>
                <td>  <span class="itemCell"><a href="/home/SeeDir?dirNew=@item.FileNamePath">@item.FileName</a></span></td>

            }
            else
            {
                <td>
                    <span>@item.FileSize</span>
                </td>
                <td>
                    <span class="itemCell" style="font-weight:bold;font-size:16px;">
                        @if (imgIs)
                        {

                            <a href="/Home/SeeImg?file=@item.FileNamePath" target="_blank">
                                <img src="/home/SeeImg?file=@item.FileNamePath" data-src="/home/SeeImg?file=@item.FileNamePath" style="height:30px;" />
                            </a>

                        }
                        @if (IsMd)
                        {

                            <a href="/Home/MDReader?file=@item.FileNamePath&title=@item.FileName" target="_blank">
                                @item.FileName
                            </a>
                            <a href="/Home/SeeFile?file=@item.FileNamePath" target="_blank">

                                <i class="layui-icon layui-icon-download-circle"></i>
                            </a>
                            <a href="/Home/WriteMD?file=@item.FileNamePath&title=@item.FileName" style=" padding-left:10px;" target="_blank">
                                编辑 <i class="layui-icon layui-icon-edit"></i>
                            </a>

                        }
                        else
                        {

                            <a href="/Home/SeeFile?file=@item.FileNamePath" target="_blank">

                                @item.FileName <i class="layui-icon layui-icon-download-circle"></i>
                            </a>
                        }
                    </span>
                </td>
            }

            @if (LoginMode.admin)
            {
                <td>

                    <i class="layui-icon layui-icon-delete" onclick="delFile('@item.FileNamePath','@ViewBag.dirNew')"></i>

                </td>
            }
        </tr>
    }
}